local jianhui = fk.CreateSkill{
    name = "jinld__jianhui",
}

Fk:loadTranslationTable{
    ["jinld__jianhui"] = "奸回",
    [":jinld__jianhui"] = "当有角色对与其势力相同的角色造成伤害时，你可以令其中一名角色摸一张牌，然后弃置其中另一名角色的一张牌。",

    ["#jinld__jianhui-choose"] = "奸回：选择一名角色摸一张牌，然后弃置另一名角色的一张牌",
    ["#jinld__jianhui-discard"] = "奸回：选择 %dest 的一张牌弃置",

    ["$jinld__jianhui1"] = "一箭之仇，十年不忘！",
    ["$jinld__jianhui2"] = "此仇不报，怨恨难消！",
}

local H = require "packages/ol_hegemony/util"

jianhui:addEffect(fk.DamageCaused,{
    anim_type = "special",
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(jianhui.name) and not data.from.dead and H.compareKingdomWith(data.from, data.to)
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local targets = {data.from, data.to}
        local to = room:askToChoosePlayers(player,{
            targets = targets,
            min_num = 1,
            max_num = 1,
            skill_name = jianhui.name,
            prompt = "#jinld__jianhui-choose",
        })
        if #to > 0 then
          event:setCostData(self, { to = to})
          return true
      end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = event:getCostData(self).to[1]
        if to.dead then return end
        if to == data.from then
            data.from:drawCards(1, jianhui.name)
            if not data.to:isNude() then
                local card = room:askToChooseCard(player,{
                    target = data.to,
                    flag = "he",
                    skill_name = jianhui.name,
                    prompt = "#jinld__jianhui-discard::"..data.to.id,
                })
            room:throwCard(card, jianhui.name, data.to, player)
        end
        elseif to == data.to then
            data.to:drawCards(1, jianhui.name)
            if not data.from:isNude() then
                local card = room:askToChooseCard(player,{
                    target = data.from,
                    flag = "he",
                    skill_name = jianhui.name,
                    prompt = "#jinld__jianhui-discard::"..data.from.id,
                })
            room:throwCard(card, jianhui.name, data.from, player)
        end
      end
    end,
})

return jianhui